﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;

using TDB;
using System.Linq.Expressions;

namespace TDBTest
{
  class Program
  {
    static void Main(string[] args)
    {
      //Thread.Sleep(2000);

      var ds = new DocumentStore();
      ds.StoreName = "123";

      TDB.Administration.AdministrationServicesClient admin = new TDB.Administration.AdministrationServicesClient();
      admin.DeployDefinitionAssembly(File.ReadAllBytes(Assembly.GetExecutingAssembly().Location));


      //Console.WriteLine("Creating Objects");
      List<post_Posts> posts = new List<post_Posts>();
      for (int i = 0; i < 100; i++)
        posts.Add(new post_Posts() { Id = i });

      //Console.WriteLine("Object Creation Completed.");
      //Console.WriteLine("Indexing started.");
      var start = DateTime.Now;
      TimeSpan elapsed;

      ds.SetCollection(posts);

      elapsed = DateTime.Now.Subtract(start);
      Console.WriteLine(elapsed.TotalMilliseconds);
      //Console.ReadLine();

      while (true)
      {
        Console.WriteLine("Query started.");
        start = DateTime.Now;

        //var rr = ds.Get<post_Posts>(p => (p.Id > 45 && p.Id < 60) || (p.Id > 120 && p.Id < 140) || p.Body.Contains("33") || p.CreationDate > DateTime.Now || p.AuthorId == Guid.Empty);
        var rr = ds.Get<post_Posts>(p => p.Id > 45);

        elapsed = DateTime.Now.Subtract(start);
        Console.WriteLine(elapsed.TotalMilliseconds);

        Console.ReadLine();
      }
    }
  }
}
